﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using S4Store.Domain;

namespace S4Store.Models
{
    public class ReportBarModel
    {
        public ReportBarModel()
        {
            ViewItems = ViewItem.None | ViewItem.SubmitButton;
        }
        public List<S4Store.Domain.Store> Stores { get; set; }
        public S4Store.Domain.Store Store { get; set; }
        public DateTime Month { get; set; }
        public DateTime? Start { get; set; }
        public DateTime? End { get; set; }
        public int? SearchSellerId { get; set; }
        public int? SearchCarBrandId { get; set; }
        public int? SearchCarModelId { get; set; }

        public String Action { get; set; }
        public String Controller { get; set; }
        public String PlusItem { get; set; }

        public bool RemoveForm { get; set; }



        public ViewItem ViewItems { get; set; }

        public bool IsView(ViewItem item)
        {
            if (ViewItems == null) { return false; }
            var r = (ViewItems & item) == item;
            return (ViewItems & item )== item;
        }
        public void AddView(ViewItem item)
        {
            if (ViewItems == null) { ViewItems = item; }
            ViewItems |= item;
        }
        public void RemoveView(ViewItem item)
        {
            if (ViewItems == null) {return; }
            ViewItem result = ViewItem.None;
            if (IsView(ViewItem.Stores) && item != ViewItem.Stores)
            {
                result |= ViewItem.Stores;
            }
            if (IsView(ViewItem.Month) && item != ViewItem.Month)
            {
                result |= ViewItem.Month;
            }
            if (IsView(ViewItem.StartEnd) && item != ViewItem.StartEnd)
            {
                result |= ViewItem.StartEnd;
            }
            if (IsView(ViewItem.SubmitButton) && item != ViewItem.SubmitButton)
            {
                result |= ViewItem.SubmitButton;
            }
            ViewItems = result;
        }
        [Flags]
        public enum ViewItem
        {
            None=0,
            Stores=1,
            Month=2,
            StartEnd=4,
            SubmitButton=8
        }
    }
}